package blow.sky.quoted.controller;


import blow.sky.quoted.entity.ClientViewResponse;
import blow.sky.quoted.entity.QuoteResponse;
import blow.sky.quoted.entity.UserViewResponse;
import blow.sky.quoted.response.MsgResponse;
import blow.sky.quoted.service.QuoteRequestService;
import blow.sky.quoted.service.QuoteResponseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName QuoteResponseController
 * @Description TODO
 * @Author 江志武
 * @Date 2021/6/1 20:31
 */
@RestController
@RequestMapping("/api/response")
public class QuoteResponseController {
    @Autowired
    QuoteResponseService service;

    //插入一条数据
    @PostMapping("/updateOne")
    public MsgResponse insertOne(@RequestBody UserViewResponse response)
    {
        boolean flag = service.insertOne(response);
        if(flag)
            return new MsgResponse("success");
        else
            return new MsgResponse("fail", "Format Error");
    }

    //查找user发送的所有信息
    @GetMapping("/fromUser/{fromUser}")
    public List<UserViewResponse> getAllByUser(@PathVariable("fromUser") String user)
    {
        return service.findByUser(user);
    }

    //查找user发送的所有信息和info
    @GetMapping("/fromUser/info/{fromUser}")
    public List<ClientViewResponse> getAllByUserAndInfo(@PathVariable("fromUser") String user)
    {
        return service.findResponseAndInfo(service.findByUser(user));
    }

    //查找所有对RequestId 的所有信息
    @GetMapping("/id/{id}")
    public List<UserViewResponse> getAllById(@PathVariable("id") long id)
    {
        return service.findByRequestId(id);
    }

    //查找所有对RequestId 的所有信息和INFO
    @GetMapping("/id/info/{id}")
    public List<ClientViewResponse> getAllByIdAndInfo(@PathVariable("id") long id)
    {
        return  service.findResponseAndInfo(service.findByRequestId(id));
    }
}
